package com.ruoyi.back.service.impl

import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
import com.ruoyi.app.common.Data
import com.ruoyi.app.common.Ok
import com.ruoyi.back.domain.AdvertisingSetting
import com.ruoyi.back.mapper.AdvertisingSettingMapper
import org.springframework.stereotype.Service

@Service
class AdvertisingSettingService : ServiceImpl<AdvertisingSettingMapper, AdvertisingSetting>() {

    fun saveAdvertisingSetting(advertisingSetting: AdvertisingSetting): Data<Boolean> =
        advertisingSetting.id?.run {
            Ok("更新设置成功", updateById(advertisingSetting))
        } ?: Ok("保存设置成功", save(advertisingSetting))

    fun getAdvertisingSetting(advertisingType: Int): Data<AdvertisingSetting> =
        Ok(
            "获取成功", getOne(
                KtQueryWrapper(AdvertisingSetting::class.java)
                    .eq(AdvertisingSetting::advertisingType, advertisingType)
            )
                ?: AdvertisingSetting()
        )

}